﻿using System;
using System.Collections.Generic;
using Gp.Scripts.Data;
using QFramework;
using UnityEngine;

namespace Gp.Scripts.Core {
    public class UnitBuffFxContainer : UnitSubObject {
        private Dictionary<object, UnitBuffFx> map = new();
        
        public void Add(BaseBuff key, UnitBuffFx fx) {
            if (fx == null) return;
            if (map.ContainsKey(key)) return;

            var item = Instantiate(fx, transform, false);
            map[key] = item;
        }


        // private void LateUpdate() {
        //     if (!Model) return;
        //         
        //     transform.forward = Model.transform.forward;
        //     var pos = Model.transform.position;
        //     transform.position = new Vector3(pos.x, transform.position.y, pos.z);
        // }


        public void Remove(BaseBuff key) {
            var target = map.GetValueOrDefault(key);
            if (target == null) return;
            
            
            target.OnFadeTrigger();
        } 
        
    }
}